package com.cookie.framework.base;

import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

/**
 * 项目名:    MeetProject
 * 包名:      com.cookie.framework.base
 * 文件名:    BasePageAdapter
 * 创建者:    cookie
 * 创建时间:   2019/12/31 21:37
 * 描述:      PagerAdapter的基类
 */

public class BasePageAdapter extends PagerAdapter {

    private List<View> list;

    public BasePageAdapter(List<View> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view,  Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ((ViewPager) container).addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        ((ViewPager) container).removeView(list.get(position));
    }
}
